package base_validate

import (
	"github.com/go-playground/validator/v10"
	"regexp"
)

func Mobile(fl validator.FieldLevel) bool {
	mobile := fl.Field().String()
	ok, _ := regexp.MatchString(`^1([38][0-9]|14[579]|5[^4]|16[6]|7[1-35-8]|9[189])\d{8}$`, mobile)
	if !ok {
		return false
	}
	return true
}

// 自定义邮箱格式校验
func Email(fl validator.FieldLevel) bool {
	emailRegex := `^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`
	// 定义更严格的邮箱正则，例如只允许 `@example.com` 结尾的邮箱
	reg := regexp.MustCompile(emailRegex)
	return reg.MatchString(fl.Field().String())
}
